package controller

import (
	"admin/contrib/session"
	"admin/model"
	"common/helper"
	"github.com/valyala/fasthttp"
)

type PrivController struct{}

/**
 * @Description: 权限列表
 * @Author: carl
 */
func (that *PrivController) List(ctx *fasthttp.RequestCtx) {

	gid := string(ctx.QueryArgs().Peek("gid"))
	if gid != "" {
		if !helper.CtypeDigit(gid) {
			helper.RetData(ctx, false, helper.GroupIDErr)
			return
		}
	}

	admin := session.AdminGet(ctx)
	adminifo, _ := model.GetAdminInfoById(admin["id"])
	// 获取权限列表
	data, err := model.PrivList(gid, adminifo.GroupID)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}

	ctx.SetBody([]byte(data))
}
